package com.zxbg.controller.systemtoolsController;

import com.zxbg.controller.Code;
import com.zxbg.controller.Result;
import com.zxbg.domain.AppCategory;
import com.zxbg.service.systemtoolsService.WorkflowTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/WorkflowType")
public class WorkflowTypeController {
    @Autowired
    WorkflowTypeService workflowTypeService;

    @GetMapping
    public Result getAllCategory(@RequestHeader Integer tenant_id) {
        return new Result(Code.GET_OK, workflowTypeService.getAllCategory(tenant_id));
    }

    @PostMapping
    public Result addCategory(@RequestBody AppCategory appCategory, @RequestHeader String tenant_id) {
        boolean flag = workflowTypeService.addCategory(appCategory, Integer.parseInt(tenant_id));
        return new Result(flag ? Code.SAVE_OK : Code.SAVE_ERR, flag);
    }

    @DeleteMapping("/{category_id}")
    public Result deleteCategory(@PathVariable("category_id") Integer category_id) {
        boolean flag = workflowTypeService.deleteCategory(category_id);
        return new Result(flag ? Code.DELETE_OK : Code.DELETE_ERR, flag);
    }

    @PutMapping
    public Result updateCategory(@RequestBody AppCategory appCategory) {
        boolean flag = workflowTypeService.updateCategory(appCategory);
        return new Result(flag ? Code.UPDATE_OK : Code.UPDATE_ERR, flag);
    }

    @PostMapping("/changeOrder")
    public Result changeOrder(@RequestBody Map<String,Integer> map, @RequestHeader Integer tenant_id) {
        boolean flag = workflowTypeService.changeOrder(map.get("oldIndex"), map.get("newIndex"), tenant_id);
        return new Result(flag ? Code.UPDATE_OK : Code.UPDATE_ERR, flag);
    }
}
